home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dr. Windows 3
/
dr win3.zip
/
dr win3
/
WINPROGS
/
WUNZ20SR.ZIP
/
WNDPROC.C
< prev
Wrap
C/C++ Source or Header
|
1993-07-12
|
42KB
|
1,025 lines
#include <sys\types.h>
#include <sys\stat.h>
#include <time.h>
#include <string.h>
#include "wizunzip.h"
#include "helpids.h"
#include <shellapi.h>
/* Windows Info-ZIP Unzip Window Procedure, wndproc.c.
* Author: Robert A. Heath, 157 Chartwell Rd., Columbia, SC 29210
* I, Robert Heath, place this source code module in the public domain.
*/
#define MAKE_TABSTOP_TABLE_ENTRY(WNDHANDLE, ID) \
{ \
TabStopTable[ID - TABSTOP_ID_BASE].lpfnOldFunc = \
(FARPROC)GetWindowLong(WNDHANDLE, GWL_WNDPROC); \
SetWindowLong(WNDHANDLE, GWL_WNDPROC, (LONG)lpfnKbd); \
TabStopTable[ID - TABSTOP_ID_BASE].hWnd = WNDHANDLE; \
}
/* Forward Refs
*/
static void GetArchiveDir(LPSTR lpszDestDir);
HWND hPatternSelectDlg; /* pattern select modeless dialog */
static UINT uCommDlgHelpMsg; /* common dialog help message ID */
static DWORD dwCommDlgHelpId = HELPID_HELP; /* what to pass to WinHelp() */
static char szFormatKeyword[2][6] = { "short", "long" };
/* Trailers are the lines just above the totals */
static char * __based(__segname("STRINGS_TEXT")) szTrailers[2] = {
" ------ -------",
" ------ ------ --- -------"
} ;
static char __based(__segname("STRINGS_TEXT")) szCantChDir[] =
"Internal error: Cannot change directory. Common dialog error code is 0x%lX.";
/* size of char in SYSTEM font in pixels */
short dxChar, dyChar;
/* button control table -- one entry for
* each of 4 entries. Indexed by the window ID relative to
* the first tabstop (TABSTOP_ID_BASE).
*/
TabStopEntry TabStopTable[TABSTOP_TABLE_ENTRIES];
static LPSTR
lstrrchr(LPSTR lpszSrc, char chFind)
{
LPSTR lpszFound = (LPSTR)0;
LPSTR lpszT;
if ( lpszSrc )
{
for (lpszT = lpszSrc; *lpszT; ++lpszT)
{
if ((*lpszT) == chFind)
lpszFound = lpszT;
}
}
return lpszFound;
}
/* Copy only the path portion of current file name into
* given buffer, lpszDestDir, translate into ANSI.
*/
static void GetArchiveDir(LPSTR lpszDestDir)
{
LPSTR lpchLast;
/* strip off filename to make directory name */
OemToAnsi(lpumb->szFileName, lpszDestDir);
if (lpchLast = lstrrchr(lpszDestDir, '\\'))
*lpchLast = '\0';
else if (lpchLast = lstrrchr(lpszDestDir, ':'))
*(++lpchLast) = '\0'; /* clobber char AFTER the colon! */
}
/****************************************************************************
FUNCTION: SetCaption(HWND hWnd)
PURPOSE: Set new caption for main window
****************************************************************************/
void
SetCaption(HWND hWnd)
{
#define SIMPLE_NAME_LEN 15
WORD wMenuState;
char szSimpleFileName[SIMPLE_NAME_LEN+1]; /* just the 8.3 part in ANSI char set */
LPSTR lpszFileNameT; /* pointer to simple filename */
BOOL fIconic = IsIconic(hWnd); /* is window iconic ? */
/* point to simple filename in OEM char set */
if ((lpszFileNameT = lstrrchr(lpumb->szFileName, '\\')) ||
(lpszFileNameT = lstrrchr(lpumb->szFileName, ':')))
lpszFileNameT++;
else
lpszFileNameT = lpumb->szFileName;
_fstrncpy(szSimpleFileName, lpszFileNameT, SIMPLE_NAME_LEN);
szSimpleFileName[SIMPLE_NAME_LEN] = '\0'; /* force termination */
OemToAnsi(szSimpleFileName, szSimpleFileName);
(void)wsprintf(lpumb->szBuffer, "%s - %s %s %s",
(LPSTR)szAppName,
(LPSTR)(szSimpleFileName[0] ?
szSimpleFileName : "(No .ZIP file)"),
(LPSTR)(!fIconic && lpumb->szUnzipToDirName[0] ? " - " : ""),
(LPSTR)(!fIconic ? lpumb->szUnzipToDirName : ""));
SetWindowText(hWnd, lpumb->szBuffer);
wMenuState = (WORD)(szSimpleFileName[0] ? MF_ENABLED : MF_GRAYED) ;
EnableMenuItem(hMenu, IDM_SELECT_ALL, wMenuState|MF_BYCOMMAND);
EnableMenuItem(hMenu, IDM_DESELECT_ALL, wMenuState|MF_BYCOMMAND);
EnableMenuItem(hMenu, IDM_SELECT_BY_PATTERN, wMenuState|MF_BYCOMMAND);
}
static void ManageStatusWnd(WORD wParam);
static void ManageStatusWnd(WORD wParam)
{
int nWndState; /* ShowWindow state */
BOOL fWndEnabled; /* Enable Window state */
if (wParam == IDM_SPLIT)
{
ShowWindow(hWndStatus, SW_RESTORE);
UpdateWindow(hWndStatus);
fWndEnabled = TRUE;
nWndState = SW_SHOWNORMAL;
}
else /* Message window goes to maximum state */
{
nWndState = SW_HIDE; /* assume max state */
fWndEnabled = FALSE;
}
wWindowSelection = wParam; /* window selection: listbox, status, both */
EnableWindow( hWndList, fWndEnabled);
UpdateWindow( hWndList);
ShowWindow( hWndList, nWndState);
if (wParam == IDM_SPLIT) /* uncover buttons */
{
UpdateButtons(hWndMain); /* restore to proper state */
}
else /* else Message window occludes buttons */
{
EnableWindow( hExtract, fWndEnabled);
EnableWindow( hTest, fWndEnabled);
EnableWindow( hDisplay, fWndEnabled);
EnableWindow( hShowComment, fWndEnabled);
}
UpdateWindow( hExtract);
ShowWindow( hExtract, nWndState);
ShowWindow( hTest, nWndState);
UpdateWindow( hTest);
ShowWindow( hDisplay, nWndState);
UpdateWindow( hDisplay);
ShowWindow( hShowComment, nWndState);
UpdateWindow( hShowComment);
if (wParam == IDM_MAX_STATUS) /* message box max'd out */
{
ShowWindow(hWndStatus, SW_SHOWMAXIMIZED);
}
SetFocus(hWndStatus);
SizeWindow(hWndMain, FALSE);
}
/****************************************************************************
FUNCTION: WizunzipWndProc(HWND, unsigned, WORD, LONG)
PURPOSE: Processes messages
MESSAGES:
WM_DESTROY - destroy window
WM_SIZE - window size has changed
WM_QUERYENDSESSION - willing to end session?
WM_ENDSESSION - end Windows session
WM_CLOSE - close the window
WM_SIZE - window resized
WM_PAINT - windows needs to be painted
WM_DROPFILES - open a dropped file
COMMENTS:
WM_COMMAND processing:
IDM_OPEN - open a new file.
IDM_EXIT - query to save current file if there is one and it
has been changed, then exit.
IDM_ABOUT - display "About" box.
****************************************************************************/
long FAR PASCAL WizunzipWndProc(HWND hWnd, WORD wMessage, WORD wParam, LONG lParam)
{
FARPROC lpfnAbout, lpfnSelectDir;
HDC hDC; /* device context */
TEXTMETRIC tm; /* text metric structure */
POINT point;
FARPROC lpfnKbd;
static int nCxBorder, nCyBorder;
switch (wMessage)
{
case WM_CREATE: /* create window */
nCxBorder = GetSystemMetrics(SM_CXBORDER);
nCyBorder = GetSystemMetrics(SM_CYBORDER);
hInst = ((LPCREATESTRUCT)lParam)->hInstance;
lpfnKbd = MakeProcInstance((FARPROC)KbdProc, hInst);
hAccTable = LoadAccelerators(hInst, "WizunzipAccels");
hBrush = CreateSolidBrush(GetSysColor(BG_SYS_COLOR)); /* background */
hMenu = GetMenu(hWnd);
/* Check Menu items to reflect WIN.INI settings */
CheckMenuItem(hMenu, IDM_RECR_DIR_STRUCT, MF_BYCOMMAND |
(uf.fRecreateDirs ? MF_CHECKED : MF_UNCHECKED));
CheckMenuItem(hMenu, (IDM_SHORT+uf.fFormatLong), MF_BYCOMMAND | MF_CHECKED);
CheckMenuItem(hMenu, IDM_OVERWRITE, MF_BYCOMMAND |
(uf.fOverwrite ? MF_CHECKED : MF_UNCHECKED));
CheckMenuItem(hMenu, IDM_TRANSLATE, MF_BYCOMMAND |
(uf.fTranslate ? MF_CHECKED : MF_UNCHECKED));
CheckMenuItem(hMenu, wLBSelection, MF_BYCOMMAND | MF_CHECKED